package com.wenlin.myproduction.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.util.FarmUtil;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.util.ValCommon;
import com.wenlin.myproduction.widget.ColorProgressView;
import com.wenlin.myproduction.widget.RoundBlueProgressBar;
import com.wenlin.myproduction.widget.RoundRedProgressBar;
import com.wenlin.myproduction.widget.RoundYellowProgressBar;

import butterknife.BindView;
import butterknife.OnClick;

public class LineProgressActivity extends BaseSwipeActivity {
    @BindView(R.id.rp1)
    RoundYellowProgressBar yellow;
    @BindView(R.id.rp2)
    RoundRedProgressBar red;
    @BindView(R.id.rp3)
    RoundBlueProgressBar blue;
    @BindView(R.id.iv_left)
    ImageView ivLeft;
    @BindView(R.id.iv_right_car)
    ImageView ivRight;
    @BindView(R.id.tv_progress)
    TextView tvProgress;
    @BindView(R.id.cpv)
    ColorProgressView cpv;
    @BindView(R.id.cpv2)
    ColorProgressView cpv2;

    private int percent;
    private int cutCount = 9;

    @Override
    public int getContentView() {
        return R.layout.activity_line_progress_bar;
    }

    public static void start(BaseActivity activity) {
        Intent intent = new Intent(activity, LineProgressActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(ValCommon.LINE_PROGRESS_BAR);
        percent = 0;
        UI.setProgress(yellow, percent);
        UI.setProgress(red, percent);
        UI.setProgress(cpv, percent);
        UI.setProgress(cpv2, percent);
        FarmUtil.initCarUI(blue, ivLeft, tvProgress, cutCount);//更新小车信息，如果作物数整十不会有动画
    }

    @OnClick({R.id.tv_add, R.id.tv_reduce, R.id.tv_add_cut_count})
    void click(View view) {
        switch (view.getId()) {
            case R.id.tv_add:
                percent += 10;
                if (percent > 100) percent -= 100;
                UI.setProgress(yellow, percent);
                UI.setProgress(red, percent);
                UI.setProgress(cpv, percent);
                UI.setProgress(cpv2, percent);
                break;
            case R.id.tv_reduce:
                percent -= 10;
                if (percent < 0) percent += 100;
                UI.setProgress(yellow, percent);
                UI.setProgress(red, percent);
                UI.setProgress(cpv, percent);
                UI.setProgress(cpv2, percent);
                break;
            case R.id.tv_add_cut_count:
                cutCount += 1;
                FarmUtil.updateCarUI(blue, ivLeft, ivRight, tvProgress, cutCount);//更新小车信息，如果作物数整十会有动画
                break;
            default:
        }
    }
}
